package com.mt.roll.upms.controller;

import com.mt.roll.core.constants.CommonConstant;
import com.mt.roll.core.params.EnabledParam;
import com.mt.roll.core.params.IdParam;
import com.mt.roll.core.validator.groups.AddGroup;
import com.mt.roll.core.validator.groups.UpdateGroup;
import com.mt.roll.core.vo.IdVo;
import com.mt.roll.core.vo.R;
import com.mt.roll.upms.params.SysPostParam;
import com.mt.roll.upms.service.PostService;
import com.mt.roll.upms.vo.SysPostVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;
import javax.validation.groups.Default;
import java.util.List;

/**
 * @Description: 合作伙伴岗位控制层
 * @Param:
 * @return:
 * @Author: tqq
 * @Date: 2019/11/11 15:44
 */
@RestController
@RequestMapping(CommonConstant.API_MODULE_UPMS +"post")
@Slf4j
@Api(value = "岗位管理", tags = "岗位管理接口")
public class PostController {
    @Autowired
    private PostService postService;

    @PostMapping(value = "get")
    @ApiOperation(value = "通过id获取岗位信息")
    private R<SysPostVo> get(@Valid @RequestBody IdParam idParam) {
        return postService.get(idParam);
    }

    @PostMapping(value = "tree")
    @ApiOperation(value = "获取岗位树形结构信息")
    private R<List<SysPostVo>> tree() {
        return postService.tree();
    }

    @PostMapping(value = "add")
    @ApiOperation(value = "新增岗位信息")
    private R<IdVo> add(@Validated({AddGroup.class, Default.class}) @RequestBody SysPostParam sysPostParam) {
        return postService.add(sysPostParam);
    }

    @PostMapping(value = "update")
    @ApiOperation(value = "修改岗位信息")
    private R<IdVo> update(@Validated({UpdateGroup.class, Default.class}) @RequestBody SysPostParam sysPostParam) {
        return postService.update(sysPostParam);
    }

    @PostMapping(value = "enabled")
    @ApiOperation(value = "启停岗位")
    private R<IdVo> enabled(@Validated @RequestBody EnabledParam enabledParam) {
        return postService.enabled(enabledParam);
    }

    @PostMapping(value = "delete")
    @ApiOperation(value = "删除岗位")
    private R<IdVo> delete(@Valid @RequestBody IdParam idParam) {
        return postService.delete(idParam);
    }

}
